package com.nbsaas.boot.project.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.CatalogEntity;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;


@CatalogClass
@ComposeView
@org.hibernate.annotations.Table(appliesTo = "bs_function", comment = "功能")
@Data
@FormAnnotation(model = "功能")
@Entity
@Table(name = "bs_function")
public class ProjectFunction extends CatalogEntity {

    @SearchItem(label = "项目应用", name = "projectApp",key = "projectApp.id",classType = Long.class,type = InputType.select)
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ProjectApp projectApp;

    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ProjectFunction parent;

    @OneToMany(fetch = FetchType.LAZY,mappedBy = "parent")
    private List<ProjectFunction> children;

    @Override
    public Serializable getParentId() {
        if (parent != null) {
            return parent.getId();
        }
        return null;
    }
}
